{extend name="base"/}
{block name="main"}
<style>.btn {margin-bottom:0;}</style>
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="{:url('goods/goodslist')}" class="n_tab_list">商品列表</a>
            <a href="{:url('goods/add_goods')}" class="n_tab_add" onclick="javascript:layer.msg('加载界面中,请稍等！',{icon:16,shade: 0.01});">
                <i class="Hui-iconfont">&#xe600;</i>添加商品
            </a>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px;display: none;" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
            <div class="cl"></div>
        </div>
                <div>
<style>.page_btn{float:left;}
	.tabBar span {background: #fff;color:#988989;font-size:14px;font-weight: normal;}</style>
                    <div class="cl pd-5 bg-1 bk-gray mt-20">
                        <form class="Huiform" method="post" action="__CONF_SITE__admin/goods/goodslist" style=" padding: 15px;">
<div class="text-c">
                            日期范围：
                            <input autocomplete="off" type="text" onfocus="WdatePicker()" value="{$star_time}" name="star_time" class="input-text Wdate" style="width:120px;">
                            -
                            <input autocomplete="off" type="text" onfocus="WdatePicker()" value="{$end_time}" name="end_time" class="input-text Wdate" style="width:120px;">
                            <input autocomplete="off" type="text" name="search_text" value="{$search_text}" placeholder=" 商品名称" style="width:250px" class="input-text">
                          <select class="input-text" name="goods_cate" style="width: auto">
                              <option value="0">全部</option>
                              {volist name="goods_cate" id="c"}
                            <option {if condition="$cate_id==$c.cate_id"} selected {/if} value="{$c.cate_id}">{$c.cate_name}</option>
                              {/volist}
                          </select>
                            <button class="btn btn-search radius" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜商品</button>
</div>
                        </form>
                    </div>
                    <div id="tab_demo" class="HuiTab" style="margin-top: 15px;">
                        <div class="tabBar clearfix">
                            <span {if condition="$status==''"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist'">全部</span>
                            <span {if condition="$status==1"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=1'">出售中</span>
                            <span {if condition="$status==2"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=2'">仓库中</span>
                            <span {if condition="$status==3"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=3'">已售罄</span>
                            <span {if condition="$status==4"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=4'">回收站</span>
                        </div>
                    </div>
<div class="cl pd-5 bg-1 bk-gray mt-20" style="padding:10px;border-bottom:0;margin-top: 15px;">
                        <span class="page_btn"><a href="javascript:;" onclick="goods_pldel()" class="btn btn-new radius"><i class="Hui-iconfont">&#xe6e2;</i> 删除</a></span>
                        <span class="page_btn" style="margin-left: 10px;margin-right: 10px;"><a href="javascript:;" onclick="goods_re()" class="btn btn-new radius"><i class="Hui-iconfont">&#xe6c1;</i> 热卖</a></span>
                        <span class="page_btn" style="margin-right: 10px;"><a href="javascript:;" onclick="goods_new()" class="btn btn-new radius"><i class="Hui-iconfont">&#xe630;</i> 新品</a></span>
                        <span class="page_btn"><a href="javascript:;" onclick="goods_tui()" class="btn btn-new radius"><i class="Hui-iconfont">&#xe6cf;</i> 推荐</a></span></div>
                    <div>
                        <table class="table table-border table-bordered table-bg table-hover table-sort" style="margin-top: 0;">
                            <thead>
                            <tr class="text-c">
                                <th><input id="xs-all" name="" type="checkbox" value=""></th>
                                <th>排序</th>
                                <th>缩略图</th>
                                <th>产品名称</th>
                                <th>单价</th>
                                <th>添加时间</th>
                                <th>状态</th>
                                <th>发布</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="tbody">
                            {volist name="result" id="r" key="k"}
                                <tr class="text-c va-m">
                                    <td><input name="sub" type="checkbox" value="{$r['goods_id']}"></td>
                                    <td style="text-align: center;"><input type="text" class="sort input-common" data-id="{$r['goods_id']}" name="sort" value="{$r['sort']}" size="1" ></td>
                                    <td><img width="60" height="60" class="radius" src="{$r['img_cover']}"></a></td>
                                    <td class="text-l">{$r['goods_name']}</td>
                                    <td><span class="price">{$r['price']}</span></td>
                                    <td>{$r['create_time']}</td>
                                    <td class="td-status">
                                        {if $r['is_new']==1}
                                        <a onclick="goods_type_all(this,'{$r.goods_id}','new')" style="text-decoration:none" href="javascript:;" title="新品"><span class="label label-secondary radius">新</span></a>
                                        {/if}
                                        {if $r['is_hot']==1}
                                        <a onclick="goods_type_all(this,'{$r.goods_id}','hot')" style="text-decoration:none" href="javascript:;" title="热销"> <span class="label label-danger radius">热</span></a>
                                        {/if}
                                        {if $r['is_recommend']==1}
                                        <a onclick="goods_type_all(this,'{$r.goods_id}','tui')" style="text-decoration:none" href="javascript:;" title="推荐"> <span class="label label-primary radius">荐</span></a>
                                        {/if}
                                        {if $r['is_hot']==0&&$r['is_new']==0&&$r['is_recommend']==0}
                                        无
                                        {/if}
                                    </td>
                                    <td class="td-status">
                                        {if $r['state']==1}
                                        <a style="text-decoration:none" onClick="goods_stop(this,'{$r.goods_id}')" href="javascript:;" title="下架"><span class="label label-success radius">已发布</span></a>
                                        {/if}
                                        {if $r['state']==0}
                                        <a style="text-decoration:none" onClick="goods_star(this,'{$r.goods_id}')" href="javascript:;" title="上架"><span class="label label-danger radius">仓库中</span></a>
                                        {/if}
                                        {if $r['stock']==0}
                                        <a style="text-decoration:none" href="javascript:;" title="已售罄"><span class="label label-warning radius">已售罄</span></a>
                                        {/if}
                                        {if $r['state']==10}
                                        <a style="text-decoration:none" href="javascript:;" title="违规商品"><span class="label label-default radius">违规商品</span></a>
                                        {/if}
                                    </td>
                                    <td class="td-manage">
                                        <a style="text-decoration:none;color:#0066cc;" class="ml-5" href="__CONF_SITE__admin/goods/add_goods&goodsId={$r.goods_id}" onclick="javascript:layer.msg('加载界面中,请稍等！',{icon:16,shade: 0.01});" title="编辑">
                                         编辑
                                        </a>
                                        <a style="text-decoration:none;color:#0066cc;" class="ml-5" onClick="goods_del(this,'{$r.goods_id}')" href="javascript:;" title="删除">删除
                                        </a><a style="text-decoration:none;color:#0066cc;" title="复制" href="javascript:void(0);" onclick="copy_now('wxpath{$k}')" id="wxpath{$k}" data-clipboard-text="yb_shop/pages/goods/detail/index?id={$r.goods_id}">复制链接</a></td>
                                </tr>
                            {/volist}
                            </tbody>
                        </table>
                        <div class="n_page_no">
                            {$page}
                        </div>
                    </div>
                </div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('#xs-all').click(function () {
            var xs_status = $('#xs-all').prop('checked');
            if (xs_status) {
                $("[name='sub']").prop('checked', true);
            }else{
                $("[name='sub']").prop('checked', false);
            }
        });
        $("[name='sub']").click(function () {
            var i = 0;
            var j = 0;
            $("[name='sub']").each(function () {
                var xs_stu = $(this).prop('checked');
                if (xs_stu) {
                    i++;
                }
                j++;
            });
            if (i == j) {
                $('#xs-all').prop('checked', true);
            } else {
                $('#xs-all').prop('checked', false);
            }
        });
    });
    /*
     参数解释：
     title	标题
     url		请求的url
     id		需要操作的数据id
     w		弹出层宽度（缺省调默认值）
     h		弹出层高度（缺省调默认值）
     */
    /*商品-状态修改*/
    function goods_type_all(obj,id,key) {
        //后台处理
        $.ajax({
            type : "post",
            url : "{:url('goods/goodTypeEdit')}",
            data : {
                "goods_id" : id,
                "key" : key
            },
            success : function(data) {
                if (data['code'] > 0) {
                    $(obj).remove();
                    layer.msg('取消成功!',{icon: 1,time:500});
                }else{
                    layer.msg(data['message'], {icon: 2, time: 1000});
                }
            }
        })
    }
	/*商品-停用*/
    function goods_stop(obj,id){
        layer.confirm('确认要下架吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/ModifyGoodsOffline')}",
                data : {
                    "goods_ids" : id
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('下架成功!',{icon: 1,time:500},function () {
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
	/*商品-上架*/
    function goods_star(obj,id){
        layer.confirm('确认要上架吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/ModifyGoodsOnline')}",
                data : {
                    "goods_ids" : id
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('上架成功!',{icon: 1,time:500},function () {
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    /*商品-删除*/
    function goods_del(obj,id){
        layer.confirm('确认要删除商品吗？',function(index){
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/deleteGoods')}",
                data : { "goods_ids" : id.toString() },
                dataType : "json",
                success : function(data) {
                    if(data["code"] > 0 ){
                        $(obj).parents("tr").remove();
                        layer.msg(data['message'], {icon: 1, time: 1000});
                    }else {
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            });
        });
    }
    /*商品-热卖商品*/
    function goods_re(){
        var id = '';
        $('#tbody input[type=checkbox]:checked').each(function() {
            if (!isNaN($(this).val())) {
                id = $(this).val() + "," + id;
            }
        });
        if (id == '') {
            layer.msg('请选择商品', {icon: 5, time: 1000});
            return false;
        } else {
            id = id.substring(0, id.length - 1);
        }
        $.ajax({
            type : "post",
            url : "{:url('goods/ModifyGoodsRecommend')}",
            data : { "goods_id" : id.toString(),"re":1},
            success : function(data) {
                if(data["code"] > 0 ){
                    layer.msg(data['message'], {icon: 1, time: 1000},function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(data['message'], {icon: 5, time: 1000});
                }
            }
        })
    }
    /*商品-推荐商品*/
    function goods_tui(){
        var id = '';
        $('#tbody input[type=checkbox]:checked').each(function() {
            if (!isNaN($(this).val())) {
                id = $(this).val() + "," + id;
            }
        });
        if (id == '') {
            layer.msg('请选择商品', {icon: 5, time: 1000});
            return false;
        } else {
            id = id.substring(0, id.length - 1);
        }
        $.ajax({
            type : "post",
            url : "{:url('goods/ModifyGoodsRecommendTui')}",
            data : { "goods_id" : id.toString(),"tui":1},
            success : function(data) {
                if(data["code"] > 0 ){
                    layer.msg(data['message'], {icon: 1, time: 1000},function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(data['message'], {icon: 5, time: 1000});
                }
            }
        })
    }
    /*商品-新品商品*/
    function goods_new(){
        var id = '';
        $('#tbody input[type=checkbox]:checked').each(function() {
            if (!isNaN($(this).val())) {
                id = $(this).val() + "," + id;
            }
        });
        if (id == '') {
            layer.msg('请选择商品', {icon: 5, time: 1000});
            return false;
        } else {
            id = id.substring(0, id.length - 1);
        }
        $.ajax({
            type : "post",
            url : "{:url('goods/ModifyGoodsRecommendNew')}",
            data : { "goods_id" : id.toString(),"new":1},
            success : function(data) {
                if(data["code"] > 0 ){
                    layer.msg(data['message'], {icon: 1, time: 1000},function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(data['message'], {icon: 5, time: 1000});
                }
            }
        })
    }
    /*商品-PL删除*/
    function goods_pldel(){
        var id = '';
        $('#tbody input[type=checkbox]:checked').each(function() {
            if (!isNaN($(this).val())) {
                id = $(this).val() + "," + id;
            }
        });
        if (id == '') {
            layer.msg('请选择商品', {icon: 5, time: 1000});
            return false;
        } else {
            id = id.substring(0, id.length - 1);
        }
        layer.confirm('确认要删除商品吗？',function(index){
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/deleteGoods')}",
                data : { "goods_ids" : id.toString() },
                dataType : "json",
                success : function(data) {
                    if(data["code"] > 0 ){
                        layer.msg(data['message'], {icon: 1, time: 1000},function () {
                            window.location.reload();
                        });
                    }else {
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            });
        });
    }
    function copy_now(id) {
        id='#'+id;
        var check=$(id).attr('data-clipboard-text');
        if(check.length<=0){
            layer.msg("链接信息有误", {icon: 2, time: 1000});
            return false;
        }
        var clipboard=new Clipboard(id);
        clipboard.on('success',function(e){
            layer.msg("链接复制成功", {icon: 1, time: 500});
        });
        clipboard.on('error', function(e) {
            layer.msg("链接信息有误", {icon: 2, time: 1000});
        });
    }
    $("input[name=sort]").change(function(){
        var id = $(this).data("id");
        var sort = $(this).val().trim();
        $.ajax({
            type:"post",
            url:"{:url('goods/ModifyGoodsSort')}",
            data:{'id':id,'sort':sort},
            dataType:"json",
            success: function (data) {
                if(data.code>0){
                    layer.msg('操作成功', {icon: 1, time: 1000},function () {
                        window.location.reload();
                    });
                }else{
                    layer.msg('操作失败', {icon: 2, time: 1000});
                }
            }
        });
    });
</script>
{/block}